package com.project.controller;

import com.project.service.IChatService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Author: zhoujinchuan
 * @Description: （）
 * @Date: 2025/2/26 9:58
 */
@RestController
@RequestMapping
public class ChatController {

    @Autowired
    private IChatService chatService;

    // todo SseEmitter

    /**
     * 普通聊天
     * @param msg
     * @return
     */
    @GetMapping(value = "chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chat(@RequestParam("msg") String msg,
                             @RequestParam(value = "netStatus",defaultValue = "false")Boolean netStatus) {
        return chatService.chat(msg,netStatus);
    }

    /**
     * 替换后聊天
     * @param msg
     * @return
     */
    @GetMapping(value = "extractChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> extractChat(@RequestParam("msg") String msg) {
        return chatService.extractChat(msg);
    }


    /**
     * 软件经理回答文档相关问题聊天
     * @param msg
     * @param userId
     * @return
     */
    @GetMapping(value = "productChat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> productChat(@RequestParam("msg")String msg,
                             @RequestParam(value = "userId",defaultValue = "1")Long userId){
        return chatService.productChat(userId,msg);
    }

    /**
     * 回答模块作用
     * @param function
     * @param userId
     * @return
     */
    @GetMapping(value = "chatFormStructuredPrompt",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chatFormStructuredPrompt(@RequestParam("function")String function,
                             @RequestParam(value = "userId",defaultValue = "1")Long userId){

        return chatService.chatFormStructuredPrompt(userId,function);
    }
}
